package cn.snailhd.utils;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;


public class PropertiesFactory {

	private static Map<String, PropertiesHelper>
		container = new HashMap<String, PropertiesHelper>();
	/**
	 * 
	 * @param propertiesPath 
	 * @param inclass 
	 * @return
	 */
	public static PropertiesHelper getPropertiesHelper(String propertiesPath,boolean inclass){
		PropertiesHelper ph = container.get(propertiesPath);
		try {
			
			if(null==ph){
				String path = propertiesPath+".properties";
				InputStream is ;
				if(inclass){
					ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
					if(null == classLoader){
						classLoader = PropertiesFactory.class.getClassLoader();
					}
					is = classLoader.getResourceAsStream(path);
				}else{
					is = new FileInputStream(path);
					
				}
				ph = new PropertiesHelper(is);
				container.put(propertiesPath, ph);
			}
			return ph;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}
	
	
	
}
